#! /usr/bin/python3
# coding=utf-8
# @time: 2025/10/30 16:28
# @Author:鹤川
import os
import time

from airtest.core.api import *

from common.conf_path import pic_login
from common.doFile import myLogger
from pages.indexPage import IndexPage
from pages.basePage import BasePage

class LoginPage(BasePage):
    # 属性
    etel = "com.kkpodcast:id/input_phone_et"
    epwd = "com.kkpodcast:id/input_password_et"
    eok = "com.kkpodcast:id/checkbox"
    ebtu = "com.kkpodcast:id/login_tv"
    # 行为
    def login(self, uname="17550010261", upwd="a12345678"):
        myLogger.info("输入用户名")
        # 输入用户名
        self.clickEle(self.etel)
        self.inputEle(self.etel, uname)
        time.sleep(1)
        # 输入密码
        myLogger.info("输入密码")
        self.clickEle(self.epwd)
        self.inputEle(self.epwd,upwd)
        time.sleep(1)
        # 勾选协议,点击同意
        myLogger.info("勾选协议")
        self.clickEle(self.eok)
        # 点击登录
        myLogger.info("点击登录")
        self.clickEle(self.ebtu)
        return self

    def go_to_indexPage(self):
        self.login()
        myLogger.info("跳转到首页")
        return IndexPage(self.poco)

    def loginOK(self):
        pic=os.path.join(pic_login,"tpl1761817225848.png")
        eMuice=Template(pic, record_pos=(0.008, 0.76),resolution=(900, 1600),)

        if exists(eMuice):
            myLogger.info("密码错误图片存在，登录失败")
            # self.go_to_indexPage().go_to_myInfoPage().logOut()
            return "登录失败"
        else:
            myLogger.info("密码错误图片不存在，登录成功，跳转到首页，进入个人中心，退出登录")
            self.go_to_indexPage().go_to_myInfoPage().logOut()
            return "登录成功"

    def login_empty_username(self):
        """验证用户名为空的提示"""
        myLogger.info("输入用户名为空")
        pic = os.path.join(pic_login, "tpl1761826154549.png")
        eMuice = Template(pic, record_pos=(0.003, 0.74),resolution=(900, 1600), )
        if exists(eMuice):
            myLogger.info("用户名为空图片存在，登录失败")
            return "登录失败"

    def login_empty_password(self):
        """验证密码为空的提示"""
        myLogger.info("输入密码为空")
        pic = os.path.join(pic_login, "tpl1761826107169.png")
        eMuice = Template(pic, record_pos=(0.023, 0.771),resolution=(900, 1600), )
        if exists(eMuice):
            myLogger.info("密码为空图片存在，登录失败")
            return "登录失败"



if __name__ == '__main__':

    login_page = LoginPage()
    login_page.login("17550010261","a12345678")
    login_page.loginOK()
    # login_page.verify_login_error()
    # login_page.exit_login()
    # login_page.verify_login_empty_password()








